Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement v2 RecvPacket rpc handler #7421

Merged

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Oct 9, 2024

Description

closes: #7354


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

@chatton chatton changed the title [WIP DONT REVIEW] Implement v2 RecvPacket rpc handler Implement v2 RecvPacket rpc handler Oct 10, 2024
@chatton chatton marked this pull request as ready for review October 10, 2024 12:17
return errorsmod.Wrap(channeltypes.ErrInvalidPacket, "receipt not found for packet")
}

multiAckBz := k.cdc.MustMarshal(&ack)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to ackBz

Comment on lines 257 to 261
suite.Require().Contains(err.Error(), tc.expError.Error())

_, ok := ck.GetPacketReceipt(path.EndpointB.Chain.GetContext(), recvPacket.SourceChannel, recvPacket.Sequence)
suite.Require().False(ok)
ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't line 261 be at 257 (and the current 257 can be removed?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge conflict mistake I think, will fix!

modules/core/04-channel/v2/keeper/packet.go Outdated Show resolved Hide resolved
Copy link
Contributor

@bznein bznein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

sonarcloud bot commented Oct 14, 2024

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple a comments, mostly nits, lgtm overall.

)

// GetPacketAcknowledgement fetches the packet acknowledgement from the store.
func (k *Keeper) GetPacketAcknowledgement(ctx context.Context, sourceID string, sequence uint64) []byte {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will eventually be needed when we add the equivalent grpc queries for v2? Lets move to keeper.go?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be channelID

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah probs just make exported

cb := k.Router.Route(pd.DestinationPort)
res := cb.OnRecvPacket(cacheCtx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, pd, signer)

if res.Status != channeltypesv2.PacketStatus_Failure {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would have a small preference for == here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean

if res.Status == channeltypesv2.PacketStatus_Async || res.Status == channeltypesv2.PacketStatus_Success

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh and flipping of handling. So if res.Status == channeltypesv2.PacketStatus_Faillure do the current else handling.

// note this should never happen as the packet data would have had to be empty.
if len(ack.AcknowledgementResults) == 0 {
sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "invalid acknowledgement results"))
return &channeltypesv2.MsgRecvPacketResponse{Result: channeltypesv1.FAILURE}, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this mean that when we remove v1 stuff this would be a proto-breaking change? (i.e Result type changing)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we'd need to add a V2 version I guess

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just return err here

@@ -296,3 +296,49 @@ func (k *Keeper) timeoutPacket(

return nil
}

// WriteAcknowledgement writes the acknowledgement to the store.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, lets move under recv impl?

// packet sender is our channel's counterparty channel id.
channel, ok := k.GetChannel(ctx, packet.DestinationChannel)
if !ok {
// TODO: figure out how aliasing will work when more than one packet data is sent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets create issue and potentially rm these TODOs?

// TODO: figure out how aliasing will work when more than one packet data is sent.
channel, ok = k.convertV1Channel(ctx, packet.Data[0].DestinationPort, packet.DestinationChannel)
if !ok {
return errorsmod.Wrap(channeltypes.ErrChannelNotFound, packet.DestinationChannel)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use v2 types no? I.e channeltypesv2 (ditto for rest)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aliasing/converting should happen in RecvPacket so this should never be reachable...

should just be error i think if not found


// set the acknowledgement so that it can be verified on the other side
k.SetPacketAcknowledgement(
ctx, packet.DestinationChannel, packet.GetSequence(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use direct access? I think we should just not gen the getters here at the end of the day.

Suggested change
ctx, packet.DestinationChannel, packet.GetSequence(),
ctx, packet.DestinationChannel, packet.Sequence,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always kinda liked the getters 😢 hot take... really I don't care tho

)

// GetPacketAcknowledgement fetches the packet acknowledgement from the store.
func (k *Keeper) GetPacketAcknowledgement(ctx context.Context, sourceID string, sequence uint64) []byte {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be channelID

)

// GetPacketAcknowledgement fetches the packet acknowledgement from the store.
func (k *Keeper) GetPacketAcknowledgement(ctx context.Context, sourceID string, sequence uint64) []byte {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah probs just make exported

// note this should never happen as the packet data would have had to be empty.
if len(ack.AcknowledgementResults) == 0 {
sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "invalid acknowledgement results"))
return &channeltypesv2.MsgRecvPacketResponse{Result: channeltypesv1.FAILURE}, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just return err here

testing/utils.go Outdated
@@ -87,6 +87,7 @@ func UnmarshalMsgResponses(cdc codec.Codec, data []byte, msgs ...codec.ProtoMars
// RequireErrorIsOrContains verifies that the passed error is either a target error or contains its error message.
func RequireErrorIsOrContains(t *testing.T, err, targetError error, msgAndArgs ...interface{}) {
t.Helper()
require.Error(t, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this?


// set the acknowledgement so that it can be verified on the other side
k.SetPacketAcknowledgement(
ctx, packet.DestinationChannel, packet.GetSequence(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always kinda liked the getters 😢 hot take... really I don't care tho

// TODO: figure out how aliasing will work when more than one packet data is sent.
channel, ok = k.convertV1Channel(ctx, packet.Data[0].DestinationPort, packet.DestinationChannel)
if !ok {
return errorsmod.Wrap(channeltypes.ErrChannelNotFound, packet.DestinationChannel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aliasing/converting should happen in RecvPacket so this should never be reachable...

should just be error i think if not found

// the OnRecvPacket callback so we need to check if the acknowledgement is already
// set on the store and return an error if so.
if k.HasPacketAcknowledgement(ctx, packet.DestinationChannel, packet.Sequence) {
return channeltypes.ErrAcknowledgementExists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we wrap with channel id / sequence?

}

if channel.CounterpartyChannelId != packet.SourceChannel {
return channeltypes.ErrInvalidChannelIdentifier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for wrapping

@chatton chatton merged commit 50ead0f into feat/ibc-eureka Oct 14, 2024
25 checks passed
@chatton chatton deleted the cian/issue#7354-implement-v2-recvpacket-rpc-handler branch October 14, 2024 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants